package com.sun.dream.fish.frontmodel.named;

import com.sun.dream.fish.util.UnChecked;

import java.io.Serializable;

/**
 * Description:  用于定义简单对象,通过name来标识唯一对象
 * Created By ljl on 2023/12/05.
 */
public interface Named extends Serializable {

    static <T extends Named> T ofName(Class<T> type, String name) {
        return UnChecked.wrap(() -> type.cast(type.getMethod("ofName", String.class).invoke(null, name)));
    }

    static <T extends Named> T ofValue(Class<T> type, String name) {
        return UnChecked.wrap(() -> type.cast(type.getMethod("ofValue", String.class).invoke(null, name)));
    }

    String name();
}
